package com.example.moduleutils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description
 * @Author WuJianFeng
 * @Date 2022/12/21 11:42
 */
public class CachedThreadPoolSingleton {
    private static volatile ExecutorService cachedThreadPool;

    private CachedThreadPoolSingleton(){

    }

    public static ExecutorService getInstance(){
        if (cachedThreadPool == null){
            synchronized (CachedThreadPoolSingleton.class){
                if (cachedThreadPool == null){
                    cachedThreadPool = Executors.newCachedThreadPool();
                }
            }
        }
        return cachedThreadPool;
    }

    public static void shutdown() {
        if (cachedThreadPool != null){
            cachedThreadPool.shutdown();
            cachedThreadPool = null;
        }
    }

}
